package com.meilai.project.controller.web.business.customer;


import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.business.customer.CustomerEditDTO;
import com.meilai.project.service.business.customer.CustomerEditFlowService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-01-13
 */
@RestController
@RequestMapping("api/web/customerEditFlow")
public class CustomerEditFlowController {

    @Autowired
    private CustomerEditFlowService service;

    @PostMapping("/saveDrafts")
    @ApiOperation("保存到草稿箱")
    public CommonResult saveDrafts(@RequestBody CustomerEditDTO dto, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.saveDrafts(dto, true, wfData_id));
    }

    @PostMapping("/saveAndStartFlow")
    @ApiOperation("保存并开启流程")
    public CommonResult saveAndStartFlow(@RequestBody CustomerEditDTO dto, @RequestParam(value = "wfData_id", required = false) Long wfData_id) {
        return new CommonResult().success(service.saveAndStartFlow(dto, wfData_id));
    }

    @PostMapping("/check")
    @ApiOperation("审核")
    public CommonResult check(@RequestBody CustomerEditDTO dto,
                              @RequestParam(value = "isReturn") Boolean isReturn,
                              @RequestParam(value = "opinion", required = false) String opinion) {
        return new CommonResult().success(service.check(dto, isReturn, opinion));
    }

    @PostMapping("/remove")
    @ApiOperation("删除流程")
    public CommonResult remove(@RequestParam("flow_id") Long flow_id, @RequestParam("wfData_id") Long wfData_id) {
        return new CommonResult().success(service.remove(flow_id, wfData_id));
    }

    @PostMapping("/actualDelete")
    @ApiOperation("彻底删除流程")
    public CommonResult actualDelete(@RequestParam("flow_id") Long flow_id, @RequestParam("wfData_id") Long wfData_id) {
        return new CommonResult().success(service.actualDelete(flow_id, wfData_id));
    }

    @GetMapping("/one")
    @ApiOperation("根据id获取流程信息")
    public CommonResult one(@RequestParam("flow_id") Long flow_id) {
        return new CommonResult().success(service.getDtoById(flow_id));
    }
}

